﻿KISSY.use("validation", function (S, Validation) {
    S.ready(function (S) {
        var All = S.all,
            form = All("#reg_frm"),
            VALID_EFFECT = "Simple",
            VALID_STYLE = "s_b",
            validator = new Validation(form[0], { warn: VALID_EFFECT, style: VALID_STYLE });

        validator.add("#reg_firstname",
        {
            required: [true, "First name is required."],
            minLength: [2, true, "At least 2 characters."],
            maxLength: [20, true, "At most 20 characters."]
        });

        validator.add("#reg_lastname",
        {
            required: [true, "Last name is required."],
            minLength: [2, true, "At least 2 characters."],
            maxLength: [20, true, "At most 20 characters."]
        });

        validator.add("#reg_email",
        {
            required: [true, "Email is required."],
            email: [true, "Email format is incorrect"]
        });

        validator.add("#reg_pwd",
        {
            required: [true, "Password is required."],
            minLength: [6, true, "At least 6 characters."],
            maxLength: [16, true, "At most 16 characters."],
            nospace: "Space is not allowed in Password."
        });

        form.on("submit", function (event) {
            var b = validator.isValid();
            if (b === false) {
                return false;
            }
        });

    });
});